package cn.tedu.sgs.notice.service.impl;

import cn.tedu.sgs.notice.mapper.NoticeMapper;
import cn.tedu.sgs.notice.pojo.dto.NoticeQuery;
import cn.tedu.sgs.notice.pojo.dto.NoticeSaveParam;
import cn.tedu.sgs.notice.pojo.entity.Notice;
import cn.tedu.sgs.notice.pojo.vo.NoticeVO;
import cn.tedu.sgs.notice.service.NoticeService;
import cn.tedu.sgs.record.pojo.dto.RecordSaveParam;
import cn.tedu.sgs.record.pojo.entity.Record;
import cn.tedu.sgs.user.pojo.dto.UserQuery;
import cn.tedu.sgs.user.pojo.vo.UserVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class NoticeServiceImpl implements NoticeService {
	@Autowired
	NoticeMapper noticeMapper;
	@Override
	public List<NoticeVO> selectNotice(NoticeQuery noticeQuery) {
		log.debug("查询用户业务,参数:{}",noticeQuery);
		List<NoticeVO> list = noticeMapper.selectNotice(noticeQuery);
		return list;
	}

	@Override
	public void saveNotice(NoticeSaveParam noticeSaveParam) {
		log.debug("保存资讯:{}",noticeSaveParam);
		Notice notice = new Notice();
		BeanUtils.copyProperties(noticeSaveParam,notice);
		if (notice.getId() == null) {
			notice.setCreateTime(new Date());
			notice.setUpdateTime(new Date());
			noticeMapper.insert(notice);
		}else {
			notice.setUpdateTime(new Date());
			noticeMapper.update(notice);
		}
	}

	@Override
	public void deleteNotice(Long id) {
		log.debug("删除资讯:{}",id);
		noticeMapper.deleteById(id);
	}
}
